<?php
	include("../Includes/FusionCharts.php");
	include("../Includes/FusionCharts_Gen.php");
	include("../Includes/DBConn.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
	<HEAD>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>UPLB DV</title>
		
		<script language="Javascript" src="../js/FusionCharts.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.min.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.fancybox-1.3.4.pack.js"></script>
		<script type="text/javascript">

		$(document).ready(function() {
			$("a#example1").fancybox();

			$("a#example2").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a#example3").fancybox({
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'	
			});

			$("a#example4").fancybox({
				'opacity'		: true,
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'none'
			});

			$("a#example5").fancybox();

			$("a#example6").fancybox({
				'titlePosition'		: 'outside',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.9
			});

			$("a#example7").fancybox({
				'titlePosition'	: 'inside'
			});

			$("a#example8").fancybox({
				'titlePosition'	: 'over'
			});

			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});

			$("#various1").fancybox({
					'titlePosition'		: 'inside',
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			$("#various3").fancybox({
					'width'				: '75%',
					'height'			: '75%',
					'autoScale'			: false,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'type'				: 'iframe'
			});

			$("#various4").fancybox({
					'padding'			: 0,
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
			});

		});

	</script>

		<link rel="stylesheet" href="../fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

	</HEAD>

	<BODY bgcolor="white">
	<CENTER>
			<?php
				$subject = $_GET['subject'];
				//echo $subject;
				if($subject=="default"){
					$snfirst = 2007;
					$snlast = 36018;
					$yearfirst = 2007;
					$yearlast = 2008;
					$graph = 'Column3D';
				}
				else{
					$snfirst = $_POST['sn_first'];
					$snlast = $_POST['sn_last'];
					$yearfirst = $_POST['year_first'];
					$yearlast = $_POST['year_last'];
					$graph = 'Column3D';
					
					
				}
				
				if($yearfirst2 == ""){
					$yearfirst2 = $yearfirst;
				}
				
				//echo $snlast;
				
				$snnumber = $snfirst.$snlast;
				$studentnumber = $snfirst."-".$snlast;
				$academicyear = $yearfirst.$yearlast;
				$ayear = $yearfirst."-".$yearlast;
					
				$link = connectToDB();

				$strQuery0 = "select * from student where studentNumber='$snnumber'";
				$result0 = mysql_query($strQuery0) or die(mysql_error());
				$ors = mysql_fetch_array($result0);
				$fullname = $ors['firstName']." ".$ors['lastName'];
				
				
				if($semester == 1){
					$semname ="First";
				}
				else if($semester == 2){
					$semname = "Second";
				}
				else if($semester == 3){
					$semname = "Third";
				}
				
								
				if($semester2 == 1){
					$semname2 ="First";
				}
				else if($semester2 == 2){
					$semname2 = "Second";
				}
				else if($semester2 == 3){
					$semname2 = "Third";
				}
				
				$schoolyear = $semname." Semester ".$ayear;
							
				$strQuery1 = "select mayts from tempStudents where studentNumber='$snnumber'";
				$result1 = mysql_query($strQuery1) or die(mysql_error());
				$ors1 = mysql_fetch_array($result1);
				$maxallowed = $ors1['mayts'];
				$length = $yearfirst + $maxallowed;
				
							
				$FC = new FusionCharts($graph,"800","400");
				$FC->setSwfPath("../FusionCharts/");
				$strParam="caption=Frequency Distribution of Grades; subcaption=$fullname; xAxisName=Grades; yAxisName=Frequency; formatNumberScale=0; decimalPrecision=0; yaxisminvalue=0; yaxismaxvalue=10; numdivlines=9";
				$FC->setChartParams($strParam);
				
				//$strXML = "<graph caption='$fullname' subCaption='$schoolyear' showBorder='1' showNames='1'  formatNumberScale='0' decimalPrecision='2' yaxismaxvalue='10'> ";
				
				
					
					// 1.00
					$strQueryuno = "select grade, courseCode, COUNT(grade) as totaluno from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='1.00'";
					$resultuno = mysql_query($strQueryuno) or die(mysql_error());
					
				
					//$strXML .= "<set name='1.00' value='" . $orsuno['totaluno'] . "' />";
					
					$FC->addDataFromDatabase($resultuno, "totaluno", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=1");
					
					//1.25
					$strQueryutf = "select grade, COUNT(grade) as totalutf from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='1.25'";
					$resultutf = mysql_query($strQueryutf) or die(mysql_error());
					
					
					$FC->addDataFromDatabase($resultutf, "totalutf", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=1.25");
					
					//1.5
					$strQueryuf = "select grade, COUNT(grade) as totaluf from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='1.50'";
					$resultuf = mysql_query($strQueryuf) or die(mysql_error());
					
					
					$FC->addDataFromDatabase($resultuf, "totaluf", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=1.50");
					
					//1.75
					$strQueryusf = "select grade, COUNT(grade) as totalusf from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='1.75'";
					$resultusf = mysql_query($strQueryusf) or die(mysql_error());
					
					
					$FC->addDataFromDatabase($resultusf, "totalusf", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=1.75");
									
									
					// 2.00
					$strQuerydos = "select grade, COUNT(grade) as totaldos from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='2.00'";
					$resultdos = mysql_query($strQuerydos) or die(mysql_error());
					
					$FC->addDataFromDatabase($resultdos, "totaldos", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=2");
				
					//2.25
					$strQuerydtf = "select grade, COUNT(grade) as totaldtf from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='2.25'";
					$resultdtf = mysql_query($strQuerydtf) or die(mysql_error());
					
					$FC->addDataFromDatabase($resultdtf, "totaldtf", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=2.25");
					
					//2.5
					$strQuerydf = "select grade, COUNT(grade) as totaldf from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='2.50'";
					$resultdf = mysql_query($strQuerydf) or die(mysql_error());
					
					$FC->addDataFromDatabase($resultdf, "totaldf", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=2.5");
					
					//2.75
					$strQuerydsf = "select grade, COUNT(grade) as totaldsf from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='2.75'";
					$resultdsf = mysql_query($strQuerydsf) or die(mysql_error());
					
					$FC->addDataFromDatabase($resultdsf, "totaldsf", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=2.75");
				
					// 3.00
					$strQuerytres = "select grade, COUNT(grade) as totaltres from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='3.00'";
					$resulttres = mysql_query($strQuerytres) or die(mysql_error());
					
					$FC->addDataFromDatabase($resulttres, "totaltres", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=3.00");
					
					//4.00
					$strQuerycuatro = "select grade, COUNT(grade) as totalcuatro from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='4.00'";
					$resultcuatro = mysql_query($strQuerycuatro) or die(mysql_error());
					
					$FC->addDataFromDatabase($resultcuatro, "totalcuatro", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=4");
					
					//5.00
					$strQuerysingko = "select grade, COUNT(grade) as totalsingko from tempSubjects where studentNumber='$snnumber' and academicYear>='$yearfirst' and academicYear<='$yearlast' and grade='5.00'";
					$resultsingko = mysql_query($strQuerysingko) or die(mysql_error());
					
					$FC->addDataFromDatabase($resultsingko, "totalsingko", "grade", "", "v_detailed.php?subject=$subject&sn_first=$snfirst&sn_last=$snlast&year_first=$yearfirst&year_last=$yearlast&grade=5");
									
					mysql_close($link);
					$FC->renderChart();
			?>
	</CENTER>
	</BODY>
</HTML>